from timeit import Timer
from datetime import *

import sys
import math


def Problem():
    """
    You are given the following information, but you may prefer 
    to do some research for yourself.
    
        * 1 Jan 1900 was a Monday.
        * Thirty days has September,
          April, June and November.
          All the rest have thirty-one,
          Saving February alone,
          Which has twenty-eight, rain or shine.
          And on leap years, twenty-nine.
        * A leap year occurs on any year evenly divisible by 4, 
        but not on a century unless it is divisible by 400.
    
    How many Sundays fell on the first of the month during the 
    twentieth century (1 Jan 1901 to 31 Dec 2000)?
    """


    #Easy way: use the built in Date module
    start = date(1900, 1, 1)
    end = date(2000, 12, 31)

    
    #Since first day is Monday, start at first Sunday
    d = date.fromordinal(start.toordinal() + 6)
    assert(d.weekday(), 6)
    
    
    #Increment every 7 days and count if start of month
    count = 0
    while (d <= end):
        if d.day == 1 and d.year > 1900:
            count += 1
        d = date.fromordinal(d.toordinal() + 7)
        # print d
        
    ans = count
    print "Answer for Problem 19 = %d" % (ans,)
    
    
if __name__ == "__main__":
    t = Timer(setup='from __main__ import Problem', stmt='Problem()').timeit(1)
    print "Execution time = %0.3f seconds" %(t,)